package cn.sangedon.review.data.controller;

import cn.sangedon.review.common.query.data.StockDayInfoQuery;
import cn.sangedon.review.common.service.data.StockDayInfoService;
import cn.sangedon.review.common.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "股票日交易数据")
@RestController
@RequestMapping("stock_day_info")
public class StockDayInfoController {
    @Autowired
    private StockDayInfoService stockDayInfoService;

    @ApiOperation("查询股票日交易数据列表")
    @PostMapping("list")
    public Result listStockDayInfo(@RequestBody StockDayInfoQuery stockDayInfoQuery) {
        return Result.okBuilder().data(stockDayInfoService.listByCondition(stockDayInfoQuery)).build();
    }

    @ApiOperation("搜索某只股票日交易数据")
    @GetMapping("seach")
    public Result search(@RequestParam(value = "keyword") String keyword,
        @RequestParam(value = "num", required = false, defaultValue = "365") Integer num) {
        return Result.okBuilder().data(stockDayInfoService.search(keyword, num)).build();
    }

    @ApiOperation("补充某个交易日交易数据中的昨日收盘价")
    @GetMapping("fill/data")
    public Result fillData(String tradeDate) {
        stockDayInfoService.fillData(tradeDate);
        return Result.ok();
    }
}
